home *** CD-ROM | disk | FTP | other *** search
- Path: chaos.kulnet.kuleuven.ac.be!usenet
- From: Andreas De Troy <Andreas.DeTroy@ped.kuleuven.ac.be>
- Newsgroups: comp.lang.c
- Subject: Optimization Q: for( i=0; i<SIZE/2; i++) ??
- Date: 20 Feb 1996 09:00:35 GMT
- Organization: KUL
- Message-ID: <4gc2jj$ojb@chaos.kulnet.kuleuven.ac.be>
- NNTP-Posting-Host: pcip194.psy.kuleuven.ac.be
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
-
- news:4g1j9n$ooe@news.csus.edu
- wleong@sfsu.edu (Jerry Leong) wrote:
- >
- >If I have the following for loop,
- > for( i=0; i< SIZE/2 ; i++).....
- >Will the code execute faster if I precompute SIZE/2 before hand and
- >do this
- > k = SIZE/2;
- > for(i=0; i<k ; i++).....
- >
- >How does this work? I mean, would SIZE/2 get computed everytime during
- >the for loop, or it simply caculated once?
-
-
- if SIZE is a (pre#defined) constant, it makes no difference.
-
- If not, an optimizing compiler should translate both expressions to the
- same code (as long as you do not alter SIZE or k inside the loop of
- course).
-
-
-